package com.anjie.powerproject.repository;

import com.anjie.powerproject.entity.PreDataDay;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;
import java.util.List;

public interface PreDataDayRepository extends JpaRepository<PreDataDay, Integer> {

    /**
     * 根据设备code和时间读取点位的预测数据
     */
    @Query(nativeQuery = true, value = "select * from pre_data_day where device_code = :code and model_version = :model and `sdate` >= :start and `sdate` < :end order by `sdate`")
    List<PreDataDay> getPreDataDayValues(@Param("code") String deviceCode, @Param("model") Integer modelVersion, @Param("start") String startTime, @Param("end") String endTime);

    /**
     * 根据设备ID和时间读取点位的预测数据,时间升序排列
     */
    @Query(nativeQuery = true, value = "SELECT data FROM pre_data_day WHERE model_version=?1 and sdate between ?2 and ?3 ORDER BY sdate ASC")
    List<BigDecimal> getPreDataDayValuesById(Integer modelVersion, String startTime, String endTime);

}
